﻿//-----------------------------------------------------------------------
// <copyright file="ProductionEngineOps.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the ProductionEngineOps struct.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Engine.EngineOperation
{
    using System.Collections.Generic;

    /// <summary>
    /// Manages collections of assertions, retractions and modifications for a given production.
    /// </summary>
    public struct ProductionEngineOps
    {
        /// <summary>
        /// List of assertions.
        /// </summary>
        private List<object> assertions;

        /// <summary>
        /// List of modifications.
        /// </summary>
        private List<object> modifications;

        /// <summary>
        /// List of retractions.
        /// </summary>
        private List<object> retractions;

        /// <summary>
        /// Gets the list of assertions.
        /// </summary>
        public IList<object> Assertions
        {
            get
            {
                return this.assertions ?? (this.assertions = new List<object>());
            }
        }

        /// <summary>
        /// Gets the list of modifications.
        /// </summary>
        public IList<object> Modifications
        {
            get
            {
                return this.modifications ?? (this.modifications = new List<object>());
            }
        }

        /// <summary>
        /// Gets the list of retractions.
        /// </summary>
        public IList<object> Retractions
        {
            get
            {
                return this.retractions ?? (this.retractions = new List<object>());
            }
        }

        /// <summary>
        /// Equlity operator.
        /// </summary>
        /// <param name="record1">The first production engine ops record.</param>
        /// <param name="record2">The second production engine ops record.</param>
        /// <returns>True or false, representing equality.</returns>
        public static bool operator ==(ProductionEngineOps record1, ProductionEngineOps record2)
        {
            return record1.Equals(record2);
        }

        /// <summary>
        /// Inequality operator.
        /// </summary>
        /// <param name="record1">The first production engine ops record.</param>
        /// <param name="record2">The second production engine ops record.</param>
        /// <returns>True or false, representing inequality.</returns>
        public static bool operator !=(ProductionEngineOps record1, ProductionEngineOps record2)
        {
            return !record1.Equals(record2);
        }

        /// <summary>
        /// Returns a hash code for the ProductionEngineOps.
        /// </summary>
        /// <returns>A hash code for the ProductionEngineOps.</returns>
        public override int GetHashCode()
        {
            return this.assertions.GetHashCode() ^ this.modifications.GetHashCode() ^ this.retractions.GetHashCode();
        }

        /// <summary>
        /// Tests this record against another record to find equality.
        /// </summary>
        /// <param name="obj">The other production engine ops record.</param>
        /// <returns>True or false, representing equality.</returns>
        public override bool Equals(object obj)
        {
            if (!(obj is ProductionEngineOps))
            {
                return false;
            }

            return this.Equals((ProductionEngineOps)obj);
        }

        /// <summary>
        /// Tests this record against another record to find equality.
        /// </summary>
        /// <param name="other">The other production engine ops record.</param>
        /// <returns>True or false, representing equality.</returns>
        public bool Equals(ProductionEngineOps other)
        {
            if (this.assertions != other.assertions)
            {
                return false;
            }

            if (this.modifications != other.modifications)
            {
                return false;
            }

            return this.retractions == other.retractions;
        }
    }
}
